package dapps.web.monitor;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import com.opensymphony.xwork2.ActionSupport;

import dapps.entity.monitor.Indicator;
import dapps.entity.user.District;
import dapps.service.monitor.MonitorManager;
import dapps.service.user.UserManager;

@SuppressWarnings("serial")
public class StaticsAction extends ActionSupport {


	@Autowired
	private MonitorManager mManager;
	@Autowired
	private UserManager uManager;
	//private HttpServletRequest request = Struts2Utils.getRequest();
	
	private Map<String, Integer> predivalues;
	private Map<String, Double> datavalues;
	private Map<String, Double> datalmvalues;
	private List<Indicator>  dataIndicatorvalues;
	private String reportDate;
	private Long districtid;
	private List<District> districtlist;

	@Override
	public String execute() throws Exception {
		int i=0;
		if(SpringSecurityUtils.getAuthority("A_ALL_DISTRICT")){
			districtlist = uManager.getDistrictlist(null,null, null);
			i=1;
		}
		//未选 或 未跨区授权
		if(districtid==null||i==0) {
			Long udistrictid = SpringSecurityUtils.getCurrentUser().getDistrict().getId();
			if(udistrictid!=null&&udistrictid>0L){
				districtid = udistrictid;
			}else{
				districtid=null;
			}
		}
		if(StringUtils.isNotBlank(reportDate)&&districtid!=null){			
			predivalues = mManager.getStaticsPredi(reportDate,0l,districtid);
			datavalues = mManager.getStaticsData(reportDate,0l,districtid);
			datalmvalues = mManager.getStaticsLastmonth(reportDate,0l,districtid);
			dataIndicatorvalues = mManager.getStaticsIndicators(reportDate,districtid);
		}		
		return SUCCESS;
	}


	public Map<String, Integer> getPredivalues() {
		return predivalues;
	}



	public List<Indicator> getDataIndicatorvalues() {
		return dataIndicatorvalues;
	}



	public void setDataIndicatorvalues(List<Indicator> dataIndicatorvalues) {
		this.dataIndicatorvalues = dataIndicatorvalues;
	}



	public void setPredivalues(Map<String, Integer> predivalues) {
		this.predivalues = predivalues;
	}



	public Map<String, Double> getDatavalues() {
		return datavalues;
	}



	public void setDatavalues(Map<String, Double> datavalues) {
		this.datavalues = datavalues;
	}



	public Map<String, Double> getDatalmvalues() {
		return datalmvalues;
	}



	public void setDatalmvalues(Map<String, Double> datalmvalues) {
		this.datalmvalues = datalmvalues;
	}


	public String getReportDate() {
		return reportDate;
	}

	public void setReportDate(String reportDate) {
		this.reportDate = reportDate;
	}


	public Long getDistrictid() {
		return districtid;
	}


	public void setDistrictid(Long districtid) {
		this.districtid = districtid;
	}


	public List<District> getDistrictlist() {
		return districtlist;
	}



	

}
